﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Mvcmediaplayer.Models;
using Mvcmediaplayer.ViewModels;
using Mvcmediaplayer.Helpers;

namespace Mvcmediaplayer.Controllers
{
    public class MovieController : Controller
    {
        mediaEntities mediaDB = new mediaEntities();

        //
        // GET: /Movie/

        public ActionResult Index(int? Id)
        {
           // Retrieve list of Videos from database
           

            // Set up our ViewModel
            //var viewModel = new VideoIndexViewModel()
            //{
            //    Videos = videos.ToList(),
            //    NumberOfVideos = videos.Count()
            //};
            const int pageSize = 8;

            var pageListVideos = new PageList(Id??0,pageSize);
            return View(pageListVideos);
        }

        //
        // GET: /Movie/Details/7
        public ActionResult Details(int id)
        {
            var video = mediaDB.Videos
                .Single(a => a.Id == id);

            return View(video);
        }

        public ActionResult Play(int id)
        {
            // Retrieve Video from database
            var VideoModel = mediaDB.Videos.Include("Comments").Include("Ratings").Where(v => v.Id == id).FirstOrDefault();

            var viewModel = new VideoBrowseViewModel()
            {
                Video = VideoModel
            };

            return View(viewModel);
        }

    }
}
